Jupyter Notebook
だいたい Colaboratory
環境づくりの話
Docker 実行環境
dockerhub のは更新されてない
Selecting an Image — Docker Stacks documentation
使うのは quay.io/jupyter/scipy-notebook かなあ
datascience は Julia や R が必要なとき
scipy + tensorflow は quay.io/jupyter/tensorflow-notebook
ベース
docker-stacks/images/base-notebook/Dockerfile at main · jupyter/docker-stacks
docker-stacks/images/docker-stacks-foundation/Dockerfile at main · jupyter/docker-stacks
quay.io/jupyter で su になりたい
Jupyter Notebook/Docker jovyanのsudoパスワードが分からない。jupyter/xxxのコンテナでroot操作する方法 | pixelbeat sandbox
docker exec -it -u root <container_id> bash
手元の vscode から繋いで copilot 使いたいやん
Develope Vertex AI notebooks in VS Code using GitHub codespaces and remote tunnels | by Michael Homme | Apr, 2024 | Medium
Remote Tunnel でつなぐ
Run VS Code Remote Tunnels in a container - DEV Community
cli だけスパッと入れるのはかっこいいけど arch の違い吸収させたいなら snapd 使うのが楽か...
ARCH=$(case $(uname -m) in x86_64) echo 'x64';; aarch64) echo 'arm64';; *) echo 'unsupported' && exit 1;; esac)
arch によって切り替えるやつ
Remote Tunnel で繋がれる側のコンテナ、どう
interpreter path は jupyter の使う conda のもの
ロードパスは調べて追加する
python -c "import pandas; print(pandas.__file__.split('/pandas')[0])"
/opt/conda/lib/python3.11/site-packages
普通に ipynb 開いてセル実行した時に remote server 聞かれるので url 入れたら良い気がするな
手元にもモジュール入ってないと Pylance がだるいなあ、やはり devcontainer なのか...
devcontainer
VSCode Dev ContainersでJupyter実行環境を作ろう
VSCode 拡張のキーバインド
Jupyter Keymap - Visual Studio Marketplace
なんか Esc でセルから出る / Enter で入るが効かない
code:keybindings.json
// jupyter
{
"key": "escape",
"command": "notebook.cell.quitEdit",
"when": "inputFocus && notebookEditorFocused && !editorHasMultipleSelections && !editorHasSelection && !editorHoverVisible && !inlineChatFocused"
},
{
"key": "enter",
"command": "notebook.cell.edit",
"when": "notebookCellListFocused && notebookEditable && !editorHoverFocused && !inputFocus && !notebookOutputInputFocused"
},
formatOnSave
code:settings.json
"notebook.formatOnSave.enabled": true,
"notebook.defaultFormatter": "charliermarsh.ruff",
Ruff で notebook はゆるめる
以下みたいに書ける
Configuring Ruff - Ruff
code:pyproject.toml
tool.ruff.lint.per-file-ignores
"__init__.py" = "E402"
"**/{tests,docs,tools}/*" = "E402"
code:pyproject.toml
"**/*.ipynb" = "I001", "E501"
Terminal で見る
$ jupyter nbconvert --to=markdown --stdout notebook.ipynb